package com.platform.server.util;


import java.lang.reflect.Field;

import java.util.HashMap;
import java.util.Map;


public class ConstantsUtil {
	public static String SYSUSERID = "0000000000000000000000000000J919";
	public static String LASTMONTHFLAG_LAST = "1";
	public static String LASTMONTHFLAG_NOTLAST = "0";
	public static String AUTOUSERNAME = "AUTORUNNER";
	
	private static Map<Integer,String> code_maps = new HashMap<Integer,String>();
	
	public static void initCodeMaps(){
		try{
			Field fields[]=Constants.ResponseCode.class.getFields();
			for(Field field :fields){
				String desc = field.getName();
				int value = field.getInt(Constants.ResponseCode.class);
				if(code_maps.containsKey(value)){
					throw new RuntimeException("response code :" + value + " existed! [" + desc + "]");
				}else{
					code_maps.put(value, desc);
				}
			}
		}catch(Exception e){
			throw new RuntimeException("初始化response code失败",e);
		}
	}
	
	public static String getCodeMsg(int code){
		return code_maps.get(code);
	}
	
	public static boolean isDebug(){
		String debugStr = ReadConfig.get("debug");
		if("true".equals(debugStr)){
			return true;
		}
		return false;
	}
	/**
	 * 获得一个字符在一个字符串中出现的次数
	 * 
	 * @param fieldNoStr
	 * @return
	 */
	public static int getNums(String fieldNoStr,char ca) {
		char[] stringArr = fieldNoStr.toCharArray();
		int j = 0;
		for (int i = 0; i < stringArr.length; i++) {
			char cd = stringArr[i];
			if (ca == cd) {
				j++;
			}
		}
		return j;
	}
}
